﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFast;
//using EntityFramework.Extensions;
using SolutionModel;

namespace SolutionDAL
{
    public class T_NavbarDAL
    {
        /// <summary>
        /// 获取所有导航包括不可用的
        /// </summary>
        /// <returns></returns>
        public List<T_Navbar> GetListAll()
        {
            PurviewDBEntities db = DBConfig.GetDBContext();
            return db.T_Navbars.OrderBy(o => o.IsDisabled).OrderByDescending(o => o.IsDisabled).ThenBy(o => o.OrderNum).ToList();

        }

        /// <summary>
        /// 通过ID获取导航
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T_Navbar GetNavbarByID(int id)
        {
            PurviewDBEntities db = DBConfig.GetDBContext();
            return db.T_Navbars.FirstOrDefault(o => o.ID == id);

        }


        /// <summary>
        /// 添加新的导航
        /// </summary>
        /// <param name="nav"></param>
        /// <returns></returns>
        public int Add(T_Navbar nav)
        {
            PurviewDBEntities db = DBConfig.GetDBContext();
            return db.T_Navbars.Insert(nav);

        }


        /// <summary>
        /// 标记：需要修改
        /// </summary>
        /// <param name="nav"></param>
        /// <returns></returns>
        public int Update(T_Navbar nav)
        {
            PurviewDBEntities db = DBConfig.GetDBContext();
            return db.T_Navbars.Update(
                new T_Navbar
                {
                    Title = nav.Title,
                    Url = nav.Url,
                    IsDisabled = nav.IsDisabled,
                    OrderNum = nav.OrderNum
                },
                o => o.ID == nav.ID
                                );

        }

    }
}
